package me.hl.concurrent;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Created by Planck on 2016/1/29.
 */
public class FutureTest implements Callable<String> {
    private int num;

    public FutureTest(int num) {
        this.num = num;
    }

    @Override
    public String call() throws Exception {
        System.out.println("sleepping 5S");
        Thread.sleep(5000);
        return String.valueOf(num);
    }

    public static void main(String args[]) throws Exception {
        ExecutorService executor = Executors.newCachedThreadPool();
        Future<String> future = executor.submit(new FutureTest(1));
        System.out.print(future.get());
        //请记得关闭线程池。。。。
        executor.shutdown();
    }
}
